package com.freedom.education.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.freedom.education.mapper.LecturerMapper;
import com.freedom.education.pojo.Lecturer;
import com.freedom.education.query.LecturerQuery;
import com.freedom.education.service.LecturerService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;

/**
 * Description: 针对表【education_lecturer(讲师)】的数据库操作Service实现
 * <p>CreateTime: 2023-03-10 16:31:09</p>
 * <p>Email: 2396598264@qq.com</p>
 *
 * @author Chb
 */

@Service
public class LecturerServiceImpl extends ServiceImpl<LecturerMapper, Lecturer> implements LecturerService {

    @Override
    @Transactional(readOnly = true)
    public Page<Lecturer> pageByCondition(LecturerQuery lecturerQuery) {
        // 后面使用 es 查询
        Integer page = lecturerQuery.getPage();
        Integer size = lecturerQuery.getSize();
        String name = lecturerQuery.getName();
        Integer level = lecturerQuery.getLevel();
        LocalDateTime beginTime = lecturerQuery.getBeginTime();
        LocalDateTime endTime = lecturerQuery.getEndTime();

        Page<Lecturer> lecturerPage = new Page<>(page, size);
        LambdaQueryWrapper<Lecturer> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.hasText(name), Lecturer::getName, name)
                .eq(level != null, Lecturer::getLevel, level)
                .ge(beginTime != null, Lecturer::getBjtCreate, beginTime)
                .le(endTime != null, Lecturer::getBjtCreate, endTime);

        page(lecturerPage, queryWrapper);
        return lecturerPage;
    }

}




